<?php
//require_once 'Zend/View.php';
Zend_Loader::LoadClass('Zend_View');
class TransactionController extends Zend_Controller_Action
{
    public function init()
    {
        Zend_Loader::loadClass('TradeRecord');
        Zend_Loader::loadClass('UnfinishTradeRecord');
        Zend_Loader::loadClass('Zend_Date');
    }
    public function indexAction()
    {
        $this->view->assign('title', 'Hello World!');
    }
    public function createsubmitAction()
    {
        $table = new TradeRecord();
        $request = $this->getRequest();
        $date = new Zend_Date();
        
        $data = array(
            'custid' => $request->getParam('custid'),
            'createddate' => new Zend_Db_Expr('CURDATE()'),
            'createdtime' => new Zend_Db_Expr('CURTIME()')
        );
        $id = $table->insert($data);    
        $this->_helper->viewRenderer->setNoRender();
        $response = $this->getResponse();
        $response->setBody("hello world".$request->getParams().$date->toString().'the id:'.$id);
        
    }
    
    public function listunfinishtradejsonAction()
    {
        $table = new UnfinishTradeRecord();
        $this->view->trade_record = $table->fetchAll();
    }
    
    public function newtradeAction()
    {
        Zend_Loader::loadClass('Zend_Json');
        $request = $this->getRequest();
        if(!$request->isXmlHttpRequest()){
            $this->view->assign('success','false');
            $this->view->assign('message','Non AJAX Request');
            $this->render('formsubmit','common',true);
        }
        $params = $request->getParamSources();
        $submitData = $request->getParam("submitData");
        $data = Zend_Json::decode($submitData, Zend_Json::TYPE_OBJECT);
        $this->view->assign('success','true');
        $this->view->assign('message',print_r($data));
        $this->render('formsubmit','common',true);
    }
}
?>